{
  游戏程序源代码

                    By Upwinded
}

program game;

{$APPTYPE CONSOLE}

uses
  interfaces,
  Windows,
  SysUtils,
  Main in 'Main.pas',
  lua52 in 'lua52.pas',
  Engine in 'Engine.pas',
  Debug in 'Debug.pas',
  Sound in 'Sound.pas',
  PicFile in 'PicFile.pas',
  map in 'map.pas',
  PakFile in 'PakFile.pas',
  Dinput in 'Dinput.pas',
  script in 'script.pas',
  ini in 'ini.pas',
  head in 'head.pas',
  UI in 'UI.pas',
  event in 'event.pas' ;

procedure SetGameFromParam;
var
  I: integer;
begin

  for I := 1 to paramcount do
    if LowerCase(paramstr(I)) = '-debug' then
      CanDebug := true
    else if LowerCase(paramstr(I)) = '-txt' then
      TxtMode := true
    else if (LowerCase(paramstr(I)) = '-w') or (LowerCase(paramstr(I)) = '-window') then
      WindowMode := true
    else if LowerCase(paramstr(I)) = '-console' then
      ConsoleMode := true;

  if not ConsoleMode then
    freeconsole;

end;

procedure SetGameFromIni;
const
  iniName = 'Upwinded.ini';
begin
  CINI.CreateFile(iniName);
  AUTOSETVIDEO := CINI.Readbool('Run', 'AUTOSETVIDEO', AUTOSETVIDEO);
  VIDEOMODE := CINI.ReadInteger('Run', 'VIDEOMODE', VIDEOMODE);
  GameFPS := CINI.Readinteger('Run', 'FPS', GameFPS);
  WindowWidth := CINI.Readinteger('Run', 'WindowWidth', WindowWidth);
  WindowHeight := CINI.Readinteger('Run', 'WindowHeight', WindowHeight);
  Cini.ClearFile;
end;

{$R game.res}

var
  MyGame: TGame;
begin

  SetGameFromParam;
  GameDebug := TDebug.Create;
  CINI := Tini.Create;
  SetGameFromIni;
  MyGame := TGame.Create;
  if MyGame.run <> 0 then
  begin
    GameDebug.AddDebugInfo('Game Run Error!');
  end;
  MyGame.ShutDown;
  MyGame.Free;
  CINI.Destroy;
  GameDebug.Destroy;

end.
